package com.yidu.hbatsams.service.Impl;

import com.github.pagehelper.PageHelper;
import com.yidu.hbatsams.dao.AtsAttachmentEmpMapper;
import com.yidu.hbatsams.dao.AtsAttachmentMapper;
import com.yidu.hbatsams.domain.AtsAttachment;
import com.yidu.hbatsams.domain.AtsAttachmentEmp;
import com.yidu.hbatsams.domain.User;
import com.yidu.hbatsams.domain.vo.UserVo;
import com.yidu.hbatsams.service.AtsAttachmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
@Service
public class AtsAttachmentServiceImpl implements AtsAttachmentService {
    @Resource
    AtsAttachmentMapper atsAttachmentMapper;
    @Override
    public List<AtsAttachment> select(AtsAttachment atsAttachment,Integer pageNum,Integer pageSize) {
        PageHelper.offsetPage(pageNum,pageSize);
        PageHelper.startPage(pageNum,pageSize);
        return atsAttachmentMapper.select(atsAttachment);
    }

    @Override
    public int selectCount(AtsAttachment atsAttachment) {
        return atsAttachmentMapper.selectCount(atsAttachment);
    }

    @Override
    public int updateByPrimaryKeySelective(AtsAttachment atsAttachment) {
        //返回根据Id智能修改的对象
        return atsAttachmentMapper.updateByPrimaryKeySelective(atsAttachment);
    }

    @Override
    public AtsAttachment selectByPrimaryKey(Integer attachId) {
        //返回根据ID查询出的对象
        return atsAttachmentMapper.selectByPrimaryKey(attachId);
    }

    @Override
    public int insert(AtsAttachment atsAttachment) {
        //返回调用增加的方法
        return atsAttachmentMapper.insert(atsAttachment);
    }
    @Resource
    AtsAttachmentEmpMapper atsAttachmentEmpMapper;

    @Override
    public List<AtsAttachment> selectEmp(HttpSession session) {
        //根据作用域的用户对象创建
        UserVo user=(UserVo)session.getAttribute("user");
        //创建对象
        AtsAttachment atsAttachment=new AtsAttachment();
        //对象属性赋值用户姓名
        atsAttachment.setAttachPublisher(user.getUserName());
        //根据对象调用查询全部方法创建泛集合
        List<AtsAttachment> list=atsAttachmentMapper.select(atsAttachment);
        //根据当前用户ID调用查询关联当前用户查询方法创建泛集合
        List<AtsAttachment> list1=atsAttachmentMapper.findEmp(user.getUserId());
        //如果用户集合不为空
        if(list1!=null){
            //以集合作条件循环
            for (AtsAttachment atsAttachmentEmp : list1) {
                //将当前对象每个加入前个集合
                list.add(atsAttachmentEmp);
            }
        }
        //返回前个集合
        return list;
    }

    @Override
    public int updateRemark(AtsAttachment atsAttachment) {
        //根据当前模型作为条件调用修改方法返回状态
        return atsAttachmentMapper.updateRemark(atsAttachment);
    }
}